package com.cw.DesignModel23.Behavioral.StatePattern;

/**
 * 使用享元模式 , 共享同一个对象
 *
 * 上下文也有 play , pause , speed , stop 等状态
 *      执行这些方法时 , 调用状态的相应方法
 */
public class VedioContext {

    /**
     * 当前的状态
     */
    private VedioState mVedioState;
    public final static PlayState PLAY_STATE = new PlayState();
    public final static PauseState PAUSE_STATE = new PauseState();
    public final static SpeedState SPEED_STATE = new SpeedState();
    public final static StopState STOP_STATE = new StopState();

    public VedioState getVedioState() {
        return mVedioState;
    }

    /**
     * 将传入的 VedioState , 赋值给当前的 VedioState mVedioState 成员
     *      除此之外 , 还要设置 VedioState 的上下文 , 即该类本身
     *      将当前的环境 VedioContext , 通知到各个状态实现类
     * @param mVedioState
     */
    public void setVedioState(VedioState mVedioState) {
        this.mVedioState = mVedioState;
        this.mVedioState.setVedioContext(this);
    }

    public void play() {
        this.mVedioState.play();
    }

    public void pause() {
        this.mVedioState.pause();
    }

    public void speed() {
        this.mVedioState.speed();
    }

    public void stop() {
        this.mVedioState.stop();
    }
}


